package com.jxtpro.controller;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.ehcache.CacheInterceptor;
import com.jfinal.plugin.ehcache.CacheName;
import com.jfinal.plugin.ehcache.EvictInterceptor;
import com.jxtpro.service.area.AreaService;
/**
 * 地区控制器
 * @author x
 *
 */
public class AreaController extends Controller{
	
	@Before(CacheInterceptor.class)
	@CacheName("areas")
	public void index(){
		Ret r = AreaService.me.initData();
		renderJson(r.get("areas"));
	}
	/**
	 * 更新地址
	 */
	@Before(EvictInterceptor.class)
	@CacheName("areas")
	public void update(){
	   Integer id = getParaToInt("id");
	   String cid = getPara("cid");
	   Integer pid = getParaToInt("pid");
	   String name = getPara("name");
	   Ret r = AreaService.me.update(id,cid,pid,name);
//	   setAttr("result", r.getData().get("result"));
	   renderJson(r);
	}
	/**
	 * 新增地区
	 */
	@Before(EvictInterceptor.class)
	@CacheName("areas")
	public void save(){
		String cid = getPara("cid");
		Integer pid = getParaToInt("pid");
		String name = getPara("name");
		Ret r = AreaService.me.save(cid,pid,name);
		renderJson(r);
	}
	@Before(EvictInterceptor.class)
	@CacheName("areas")
	public void delete(){
		Integer cid = getParaToInt("cid");
		Ret r = AreaService.me.delete(cid);
		renderJson(r);
	}
	
}
